package com.njwb.consumer.config;

import com.njwb.consumer.exception.OpenFeignException;
import feign.Logger;
import feign.Response;
import feign.codec.ErrorDecoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FeignConfig {
    @Bean
    Logger.Level feignLoggerLevel() {
        return Logger.Level.FULL;
    }

    @Bean
    public ErrorDecoder feignErrorDecoder() {
        System.out.println("feignErrorDecoder()");
        return new ErrorDecoder() {
            @Override
            public Exception decode(String methodKey, Response response) {
                return new OpenFeignException(response.status(),"统一异常处理");
            }
        };
    }
}